﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using AjaxControlToolkit;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class ShareVPSL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["mtype"] == null)
            {

                Page.DataBind();
            }
            else
            {
                SqlDataSource1.SelectCommand += " where  mtype =" + Request.QueryString["mtype"] + " order by id desc";
       
                Page.DataBind();
                allcompanies.SelectedValue = Request.QueryString["mtype"];
            }
        }

    }
    
    protected void comps_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (allcompanies.SelectedValue == "-1")
        {

            Response.Redirect("~/ShareVPSL.aspx");
        }
        else
        { 
        Response.Redirect("~/ShareVPSL.aspx?mtype="+allcompanies.SelectedValue); 
        }
       
    }
    protected override void InitializeCulture()
    {
        base.InitializeCulture();
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat = new System.Globalization.CultureInfo("en-US", false).DateTimeFormat;


            }
        }
    }
    public void submits()
    {
        List<string> fields = new List<string>();
        ArrayList values = new ArrayList();
        List<string> types = new List<string>();
        ///////////////



        fields.Add("mtype");
        types.Add("int");
        values.Add(p_or_v.Value=="v"?1:2);
        ////////////////////////////////////
        if (ups_or_lk.Value == "ups")
        {
            if (AsyncFileUpload1.HasFile)
            {
                fields.Add("scomment");
                types.Add("string");
                values.Add(mycomment.Text);
                /////////////////////////////////////////////////
                ///////////////////////
                fields.Add("link");
                types.Add("string");
                values.Add("uploads/" + AsyncFileUpload1.FileName);
            }

        }
        else
        {
            if (mylink.Text != "")
            {

                fields.Add("scomment");
                types.Add("string");
                values.Add(mycomment.Text);
                /////////////////////////////////////////////////
                ///////////////////////
                fields.Add("link");
                types.Add("string");
                values.Add(mylink.Text);
            }
           
        }

        
            DB.INSERT("media", fields, types, values);
            if (AsyncFileUpload1.HasFile)
            {
                string paths = Server.MapPath(Request.ApplicationPath) + "\\uploads\\" + AsyncFileUpload1.FileName;
                AsyncFileUpload1.SaveAs(paths);
                AsyncFileUpload1.ClearAllFilesFromPersistedStore();
            }
            Response.Redirect("~/ShareVPSL.aspx");
       
       
    
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        submits();   
    }
    protected void close_Click(object sender, EventArgs e)
    {
        string id = ((ImageButton)sender).CommandArgument;
        DB.DELETE("media", "int,id," + id);
        DataList1.DataBind();
    }
    protected void end_Click(object sender, EventArgs e)
    {
        if (AsyncFileUpload1.HasFile || (mylink.Text != ""))
        {

            submits();
           DataList1.DataBind();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "alert('لم يتم ادخال بيانات صحيحة');", true);
        }
    }

    
}
